#!/bin/sh
path=/usr/local/
pcreversion=8.44
nginxversion=1.19.0
yum -y install wget
yum -y install gcc gcc-c++ pcre-deveil zlib-devel openssl openssl-devel automake autoconf libtool make -y
yum -y install gcc-c++
yum -y install openssl openssl-devel
cd ${path}
#安装pcre支持Rewrite 功能
pcre() {
   cd ${path}
   wget -c  http://downloads.sourceforge.net/project/pcre/pcre/${pcreversion}/pcre-${pcreversion}.tar.gz
   tar zxvf pcre-${pcreversion}.tar.gz
   cd pcre-${pcreversion}
   ./configure
   make && make install
   pcre-config --version
}
#安装nginx
nginxinstall() {
  cd ${path}
  wget -c  http://nginx.org/download/nginx-${nginxversion}.tar.gz
  tar -zxvf nginx-${nginxversion}.tar.gz
  cd nginx-${nginxversion}
  ./configure --prefix=${path}nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=${path}/pcre-${pcreversion}
  make
  make install
  ${path}nginx/sbin/nginx -v
  cd ${path} && rm -rf pcre-${pcreversion}.tar.gz
  rm -rf nginx-${nginxversion}.tar.gz
}
# 初始化基础环境
install() {
  echo "start install pcre "	
  pcre
  sleep 5
  echo "start install nginx"
  nginxinstall
  echo "nginx install successfully "
  #启动nginx
  ${path}nginx/sbin/nginx
}
usage() {
  echo "Usage: sh nginx.sh [install]"
  exit 1
}
#根据输入参数，选择执行对应方法，不输入则执行使用说明
case "$1" in
    "install")
      install
      ;;
esac
exit 0
